ioemu: Two qcow2 bug fixes from upstream qemu.
authorKeir Fraser <keir.fraser@citrix.com>
Thu, 27 Mar 2008 17:14:41 +0000 (17:14 +0000)
committerKeir Fraser <keir.fraser@citrix.com>
Thu, 27 Mar 2008 17:14:41 +0000 (17:14 +0000)
[Qemu-devel] PATCH: qcow2 image corruption
http://lists.gnu.org/archive/html/qemu-devel/2007-03/msg00773.html

[Qemu-devel] [PATCH] qcow2: release refcount table clusters of the old
table, after growing the refcount table
http://lists.gnu.org/archive/html/qemu-devel/2007-04/msg00043.html

Signed-off-by: Kevin Wolf <kwolf@suse.de>
tools/ioemu/block-qcow2.c

index a5f825538957e5841ca02ed9d48fb89259229a4c..64ec49034afa02f254d1b4b3f36a5abcae778ab0 100644 (file)
@@ -1886,6 +1886,8 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
     int64_t table_offset;
     uint64_t data64;
     uint32_t data32;
+    int old_table_size;
+    int64_t old_table_offset;
 
     if (min_size <= s->refcount_table_size)
         return 0;
@@ -1931,10 +1933,14 @@ static int grow_refcount_table(BlockDriverState *bs, int min_size)
                     &data32, sizeof(data32)) != sizeof(data32))
         goto fail;
     qemu_free(s->refcount_table);
+    old_table_offset = s->refcount_table_offset;
+    old_table_size = s->refcount_table_size;
     s->refcount_table = new_table;
     s->refcount_table_size = new_table_size;
+    s->refcount_table_offset = table_offset;
 
     update_refcount(bs, table_offset, new_table_size2, 1);
+    free_clusters(bs, old_table_offset, old_table_size * sizeof(uint64_t));
     return 0;
  fail:
     free_clusters(bs, table_offset, new_table_size2);